# 1.中间件是request和response之间的处理过程中的插件
# request --> views --> response
# 和上下文处理器一样，自定义在那个文件下，然后在setting配置就好
# def front_user_middlewares(get_response):
#     初始化代码，刚启动就执行
#     def middlewares(request):
#         print("request到view")
#         # 之前的代码是request --> view
#         response = get_response(request)
#         # 之后的代码是response -->浏览器执行
#         print("response -->浏览器执行")
#         return response
#     return middlewares

# 2.内置中间件
# MIDDLEWARE = [
#     'django.middleware.security.SecurityMiddleware',
#     'django.contrib.sessions.middleware.SessionMiddleware',
#     'django.middleware.common.CommonMiddleware',
#     # 'django.middleware.csrf.CsrfViewMiddleware',
#     'django.contrib.auth.middleware.AuthenticationMiddleware',
#     'django.contrib.messages.middleware.MessageMiddleware',
#     'django.middleware.clickjacking.XFrameOptionsMiddleware',
#     'front.middlewares.front_user_middlewares'
# ]

# CommonMiddleware:
# a.比如url写成login ，它会自动给你重定向到login/, 如果注释掉就不行
# b.限制请求user-agent

# GzipMiddleware: 将response返回的内容进行压缩，前提是大于200
# SessionMiddleware：处理session对象
# 中间有写的顺序